﻿using System;
using System.Collections.Generic;
namespace exp2
{
    //照片类,用于存储照片信息
    class Photo
    {
        public string _title;
        public Photo(string title)
        {
            this._title = title;
        }
        //获取title索引器
        public string Title
        {
            get
            {
                return _title;
            }
        }
    }
    //相册类 用于存放照片对象
    class Album
    {
        Photo[] photos;
        //Album 初始化相册大小
        public Album(int capacity)
        {
            this.photos = new Photo[capacity];
        }
        //索引器
        public Photo this[int index]
        {
            get
            {
                // 验证索引范围
                if (index < 0 || index >= photos.Length)
                {
                    Console.WriteLine("索引无效");
                    // 使用 null 指示失败
                    return null;
                }
                // 对于有效索引，返回请求的照片
                return photos[index];
            }
            set
            {
                if (index < 0 || index >= photos.Length)
                {
                    Console.WriteLine("索引无效");
                    return;
                }
                photos[index] = value;
            }
        }

    }

    //Person 一个基类
    class Person { }

    //收作业接口
    public interface IHomeworkC
    {
        void CollectHomework();
    }

    //学生类
    class Student : Person, IHomeworkC
    {
        public void CollectHomework()
        {
            Console.WriteLine("报告老师！作业收集完毕！");
        }
    }

    //教师类
    class Teacher : Person, IHomeworkC
    {
        public void CollectHomework()
        {
            Console.WriteLine("同学们，请交作业！");
        }
    }

    //储蓄卡类
    class depositCard
    {
        //储蓄名
        private string name;
        //储蓄金额
        private int depositMoney;
        //基础储蓄金额
        public depositCard(string name, int money)
        {
            this.name = name;
            this.depositMoney = money;
        }
        //获取储蓄金额
        public int getDepositMoney()
        {
            return this.depositMoney;
        }
        public void setDepositMoney(int r)
        {
            this.depositMoney = r;
        }
    }

    //信用卡类
    class creditCard
    {
        //信用卡持有者名称
        public string name;
        //信用卡余额
        public int creditMoney;
        //扣款日期
        public int dueDay;
        //绑定储蓄卡对象
        public depositCard DC;
        //初始化
        public creditCard(string name, int CM, int DD, depositCard DC)
        {
            this.name = name;
            this.creditMoney = CM;
            this.dueDay = DD;
            this.DC = DC;
        }
        //还款
        public void repayM()
        {
            Console.WriteLine("用户{0}当前金额{1}",this.name, this.DC.getDepositMoney());
            DC.setDepositMoney(this.DC.getDepositMoney() + creditMoney);
            Console.WriteLine("用户已还款");
            Console.WriteLine("还款金额:{0}", Math.Abs(this.creditMoney));
            Console.WriteLine("余下金额为{0}", DC.getDepositMoney());
            Console.WriteLine();
        }
        //无需还款
        public void norepayM()
        {
            Console.WriteLine("用户{0}当前金额{1}", this.name, this.DC.getDepositMoney());
            Console.WriteLine("用户未到还款日期，无需还款", this.name);
            Console.WriteLine();
        }
    }

    //扣款委托类
    class repayDelegate
    {
        //扣款委托
        public delegate void repayMoney();
        //扣款事件
        public event repayMoney DoRepay;
        //事件执行
        public void NotifyRepay()
        {
            if (DoRepay != null)
            {
                Console.WriteLine("触发事件：");
                // 触发事件
                DoRepay();
            }
        }
    }

    class Program
    {
        //接口方法
        private static void DoCollectHomework(IHomeworkC homeworkC)
        {
            homeworkC.CollectHomework();
        }
        static void Main(string[] args)
        {
            //初始化数据
            depositCard D1 = new depositCard("张三", 10000);
            depositCard D2 = new depositCard("李四", 10000);
            depositCard D3 = new depositCard("王五", 10000);

            creditCard C1 = new creditCard("张三", -5000, 5, D1);
            creditCard C2 = new creditCard("李四", -3000, 31, D2);
            creditCard C3 = new creditCard("王五", -1000, 5, D3);
            List<creditCard> cCards = new List<creditCard>();
            cCards.Add(C1);
            cCards.Add(C2);
            cCards.Add(C3);
            //创建委托对象
            repayDelegate rD = new repayDelegate();

            foreach (creditCard C in cCards)
            {
                //判断是否到了该还款的日期
                if (C.dueDay == int.Parse(DateTime.Now.ToString("yyyy-MM-dd").Split('-')[2]))
                {
                    //事件添加
                    rD.DoRepay += new repayDelegate.repayMoney(C.repayM);
                }
                else
                {
                    rD.DoRepay += new repayDelegate.repayMoney(C.norepayM);
                }
            }
            //事件执行
            rD.NotifyRepay();
        }
    }
}

/*
//创建相册对象
Album familyAlbum = new Album(5);
//创建相片对象
Photo photo1 = new Photo("jack");
Photo photo2 = new Photo("wnedey");
Photo photo3 = new Photo("dirike");
Photo photo4 = new Photo("lisa");
Photo photo5 = new Photo("qin");
//使用索引器的set功能
familyAlbum[0] = photo1;
familyAlbum[1] = photo2;
familyAlbum[2] = photo3;
familyAlbum[3] = photo4;
familyAlbum[4] = photo5;
//使用索引器的get功能
Console.WriteLine(familyAlbum[0].Title);
Console.WriteLine(familyAlbum[1].Title);
Console.WriteLine(familyAlbum[2].Title);
Console.WriteLine(familyAlbum[3].Title);
Console.WriteLine(familyAlbum[4].Title);
Console.ReadLine();
*/

/*
    //教师 接口对象
    IHomeworkC s = new Teacher();
    DoCollectHomework(s);
    //学生 接口对象
    s = new Student();
    DoCollectHomework(s);
 */

/*
    //初始化数据
    depositCard D1 = new depositCard("张三", 10000);
    depositCard D2 = new depositCard("李四", 10000);
    depositCard D3 = new depositCard("王五", 10000);

    creditCard C1 = new creditCard("张三", -5000, 5, D1);
    creditCard C2 = new creditCard("李四", -3000, 31, D2);
    creditCard C3 = new creditCard("王五", -1000, 5, D3);
    List<creditCard> cCards = new List<creditCard>();
    cCards.Add(C1);
    cCards.Add(C2);
    cCards.Add(C3);
    //创建委托对象
    repayDelegate rD = new repayDelegate();

    foreach (creditCard C in cCards)
    {
        //判断是否到了该还款的日期
        if (C.dueDay == int.Parse(DateTime.Now.ToString("yyyy-MM-dd").Split('-')[2]))
        {
            //事件添加
            rD.DoRepay += new repayDelegate.repayMoney(C.repayM);
        }
        else
        {
            rD.DoRepay += new repayDelegate.repayMoney(C.norepayM);
        }
    }
    //事件执行
    rD.NotifyRepay();
*/